package tech.horgee.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import tech.horgee.common.IWrapper;
import tech.horgee.group.InsertGroup;

import java.io.Serializable;
import java.util.Objects;

/**
 * 角色和菜单关联表
 *
 * @author haojun
 * @since 2022-06-14
 */
@Getter
@Setter
@TableName("tab_role_menu")
public class RoleMenu implements Serializable, IWrapper<RoleMenu> {

    private static final long serialVersionUID = 1L;

    /**
     * 角色ID
     */
    @TableId(type = IdType.INPUT)
    @NotNull(groups = InsertGroup.class)
    private Long roleId;

    /**
     * 菜单ID
     */
    @NotNull(groups = InsertGroup.class)
    private Long menuId;

    @Override
    public LambdaQueryWrapper<RoleMenu> wrapper() {
        return new LambdaQueryWrapper<RoleMenu>()
                .eq(Objects.nonNull(roleId), RoleMenu::getRoleId, roleId)
                .eq(Objects.nonNull(menuId), RoleMenu::getMenuId, menuId)
                ;
    }
}
